#include <iostream>
#include <tuple>
#include <algorithm>
#include <vector>
#include "stack.h"

using namespace std;

int main()
{
    Stack<char> *s = new Stack<char>(100);
    string brackets = "[()][()()][()[()]][[()]";
    vector<char> left_brackets = {'(', '{', '['};
    for (char c : brackets)
    {
        if (find(left_brackets.begin(), left_brackets.end(), c) != left_brackets.end())
        {
            s->Push(c);
        }
        else
        {
            bool success;
            char element;
            switch (c)
            {
            case ')':
                if (tie(success, element) = s->Pop(), !(success && element == '('))
                {
                    cout << "Error: unmatched brackets" << endl;
                    goto END;
                }
                break;
            case ']':
                if (tie(success, element) = s->Pop(), !(success && element == '['))
                {
                    cout << "Error: unmatched brackets" << endl;
                    goto END;
                }
                break;
            case '}':
                if (tie(success, element) = s->Pop(), !(success && element == '{'))
                {
                    cout << "Error: unmatched brackets" << endl;
                    goto END;
                }
                break;
            }
        }
    }
    if (s->IsEmpty())
    {
        cout << "Success: all brackets are matched" << endl;
    }
    else
    {
        cout << "Error: unmatched brackets" << endl;
    }
END:
    return 0;
}